﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using CMS.BLL;

public partial class Controls_News_ctrProjects : System.Web.UI.UserControl
{
    private int nPageCount = 0;
    private int nCurrentLanguage = Support.GetCurrentLanguage() -1;
    private int nDefaultLanguage = Support.GetDefaultLanguage();
    private int nPageSize = Config.PAGESIZE;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindDataProjects(1);
        }
    }
    private void BindDataProjects(int CurrentPageIndex)
    {
        int nCat = 68;
        News objProject = new News();
        DataTable dtbProject = new DataTable();
        dtbProject = objProject.Search(0, 0, "", nCat, nDefaultLanguage, nCurrentLanguage, EnumeType.ACTIVE, CurrentPageIndex, nPageSize, ref nPageCount);
        rptProjects.DataSource = dtbProject;
        rptProjects.DataBind();
        lblTitleProjects.Text = MultipleLanguage.PROJECTS[nCurrentLanguage - 1];
        lblMapProject.Text = MultipleLanguage.PROJECTS[nCurrentLanguage - 1];
    }
    protected void rptProjects_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblTitleProject = (Label)e.Item.FindControl("lblTitleProject");
            Literal ltrContentProject = (Literal)e.Item.FindControl("ltrContentProject");
            Image imgProject = (Image)e.Item.FindControl("imgProject");
            HyperLink lnkimgProduct = (HyperLink)e.Item.FindControl("lnkimgProduct");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "NewsID"));
            lblTitleProject.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "NewsTitle"));
            ltrContentProject.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent"));
            string ImgUrl = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            if (ImgUrl == "")
            {
                imgProject.ImageUrl = Config.ROOT + Config.IMAGE_NO_IMAGE_FRONTEND;

            }
            else { imgProject.ImageUrl = Config.ROOT + Config.IMAGE_NEWS_DEFAULT_UPLOAD + ImgUrl; }
            lnkimgProduct.NavigateUrl = Config.ROOT + Pages.FrontEnds.PROJECT_DETAILS + "?" + Config.PAGE_ID + "=" + nID;

        }
    }
}